<?php
class ProductDetail_Model_Things extends Zend_Db_Table{
	protected $_name = 'things';
	protected $_primary = 'thing_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	/* select demo */
	
	public function getThingById($thingId)
	{// co dung
			$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/things/route/getThingById/id/".$thingId);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	
	
	public function updateViewThing($id,$views)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/things/route/updateViewThing/id/".$id."/view/".$views);
		
		$result = $this->getThingById($id);
		Util::update_index($result[0], $result[0]['type'],"update");
		
		return $return->getBody();
	}
	
	public  function  deletething($id)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/things/route/deletething/id/".$id);
		
		$result = $this->getThingById($id);	
		Util::update_index($result[0], $result[0]['type'],"delete");
		
		return $return->getBody();
	}
	public function updateThing($id, $data)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$data['route'] = "updateThing";
		$data['id'] = $id;
		$return = $client->restPost("/things", $data);
		
		$result = $this->getThingById($id);
		Util::update_index($result[0], $result[0]['type'],"update");
		
		return $return->getBody();
	}
	
}
?>